<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MlcmsAgentmoneylog extends Model
{
    protected $table="mlmcms_agent_moneylog";
    public $timestamps=false;
    protected $fillable = [];
    protected $guarded =[];
    protected $primaryKey = "MAMID";
    
    /**
     * 电子币充值
     * @param \Illuminate\Http\Request $request
     */
    public static function AddAgentMoneylog(\Illuminate\Http\Request $request) {
        $user = $request->session()->get("Home");
        if ($request->input("Mam_AddMoney") < 1) {
            return aaa_return(0, "请正确操作充值");
        }
        //添加一条记录，后台审核通过之后才会给会员加钱
        $data['Mag_Number'] = $user->Mu_Number;
        $data['Mam_OldMoney'] = $user->Mu_BuyFunds;
        $data['Mam_AddMoney'] = $request->input("Mam_AddMoney");
        $data["Mam_AllMoney"] =  $data['Mam_OldMoney'] + $data['Mam_AddMoney'];
        $data['Mam_IsApproved'] = 0;
        $data['Mam_ApprovedTime'] = null;
        $data['Mam_CreateTime'] = date("Y-m-d H:i:s");
        $data['Mam_Type'] = 1;
        if (!static::insert($data)) {
            return aaa_return(0, "申请失败");
        }
        return aaa_return(1, "申请提交成功，我们会抓紧审核！！");
    }
    /**
     * 获取类型
     */
    public function getType() {
        switch($this->Mam_Type) {
            case 1:
                return "电子币充值";
            case 2:
                return "奖金币充值";
        }
    }
    /**
     * 审核状态
     */
    public function getApproved() {
        return $this->Mam_IsApproved ? "已审核" : "未审核";
    }
    
}
